package storage;

import java.awt.Color;
import java.util.LinkedList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

public class BottomPane {

	public JPanel bottom_pane = new JPanel();
	public Storage storage;
	public LinkedList<JButton> btns = null;
	
	
	public BottomPane(Storage storage) {
		this.storage = storage;
		bottom_pane.setBounds(10, 600, 1200, 20);
		bottom_pane.setLayout(null);
		
	}
	
	public void refreshBtns(){
		if(btns!=null){
			for (JButton btn : btns) {
				bottom_pane.remove(btn);
			}
		}
		
		btns = new LinkedList<JButton>();
		int distance = 0;
		int pro_num = -1;
		for(Processk p : storage.pros){
			JButton btn = new JButton();
			btn.setBounds(distance, 0, p.getMemory()/10, 20);
			distance += (p.getMemory()/10);
			if(p.getPname().equals("ϵͳ")){
				btn.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2));
			}else{
				pro_num++;
				btn.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
				if(storage.mid.getJtable().getSelectedRow()==pro_num){
					btn.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
				}
			}
			bottom_pane.add(btn);
			btns.add(btn);
		}
		bottom_pane.updateUI();
	}
	
}
